* Bernd Beber, Michael J. Gilligan, Jenny Guardado, and Sabrina Karim
* Stata/MP 15 code to replicate analysis for "The Promise and Peril of Peacekeeping Economies"

* load data for cross-country analysis
    use BGGK_ISQ_data_macro

* declare time-series cross-sectional data
    tsset countrynum year

* Table 1
    * growth in per capita GDP as function of UN PK
    * include country and year fixed effects, ten-year lags for conflict indicators
    reg growthpc unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum
    * limit to countries that have experienced major conflict
    reg growthpc unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if evermajorconflict==1
    * limit to post-conflict (i.e. have had conflict in last ten years but are currently peaceful)
    reg growthpc unpkm L(1/9).conflict L(1/9).lndeaths i.year i.countrynum if conflict==0 & past10conflict>0 & past10conflict!=.
    * limit to post-Cold War era
    reg growthpc unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if year>1989
    * coarsened exact matching, with each cross-section balanced separately
    * install cem package, if needed
    * ssc install cem
    loc controls = "past5conflict lnpast5deaths gdp lnpop ethfrac lmtnest colbrit colfra"
    forvalues i = 1950/2008 {
        tempfile w`i'
        preserve
            keep if year==`i'
            cap cem `controls', tr(unpkm)
            cap gen cem_weights=.
            keep countryname year cem_weights
            save `w`i''
        restore
    }
    gen cem_weights=.
    forvalues i = 1950/2008 {
        merge 1:1 countryname year using `w`i'', update
        drop _merge
    }
    reg growthpc unpkm [iweight=cem_weights]
    tsset countrynum year

* Table 2
    * include country and year fixed effects, ten-year lags for conflict indicators
    reg growthpc lndepunpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum
    * limit to countries that have experienced major conflict
    reg growthpc lndepunpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if evermajorconflict==1
    * limit to post-conflict (i.e. have had conflict in last ten years but are currently peaceful)
    reg growthpc lndepunpkm L(1/9).conflict L(1/9).lndeaths i.year i.countrynum if conflict==0 & past10conflict>0 & past10conflict!=.
    * limit to post-Cold War era
    reg growthpc lndepunpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if year>1989
    * limit to country-years with peacekeeping, without fixed effects because of small sample
    reg growthpc lndepunpkm L(0/9).conflict L(0/9).lndeaths if unpkm==1

* Table 3
    * difference-in-differences
    reg d.growthpc d.unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum

* Table 4
    * changes in PKM status are either deployments or withdrawals, and effects differ
    * deployments
    reg d.growthpc d.unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if ((unpkm==1 & L.unpkm==0) | (unpkm==0 & L.unpkm==0) | (unpkm==1 & L.unpkm==1))
    * withdrawals
    tempvar unabs
    recode unpkm (1=0) (0=1), gen(`unabs')
    reg d.growthpc d.`unabs' L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if ((`unabs'==1 & L.`unabs'==0) | (`unabs'==0 & L.`unabs'==0) | (`unabs'==1 & L.`unabs'==1))

* Table S.1
    * post-Cold War, major conflict only
    reg growthpc unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if evermajorconflict==1 & year>1989
    * with five-year conflict histories
    reg growthpc unpkm L(0/4).conflict L(0/4).lndeaths i.year i.countrynum
    * include lagged DV (single and five-year lags)
    reg growthpc unpkm L.growthpc L(0/9).conflict L(0/9).lndeaths i.year i.countrynum

* Table S.2
    * infant mortality as an alternative outcome
    reg infantmort unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum
    reg infantmort unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if evermajorconflict==1
    reg infantmort unpkm L(1/9).conflict L(1/9).lndeaths i.year i.countrynum if conflict==0 & past10conflict>0 & past10conflict!=.
    reg infantmort unpkm L(0/9).conflict L(0/9).lndeaths i.year i.countrynum if year>1989

* load Liberia data for micro-level analysis
    use BGGK_ISQ_data_micro, clear

* declare survey design
    svyset psu [pweight=pweight], fpc(fpc1) || _n, fpc(fpc2) strata(stratum) singleunit(certainty)

* in-line estimates
    * employees with at least 10% foreign customer base
    gen temp=1 if share_foreign>=.1 & share_foreign!=.
    replace temp=0 if temp==. & share_foreign!=.
    svy: mean temp
    drop temp
    * employees selling to any foreigners
    gen temp=1 if share_foreign==0
    replace temp=0 if temp==. & share_foreign!=.
    svy: mean temp
    drop temp
    * employees with all foreign customer base
    gen temp=1 if share_foreign==1
    replace temp=0 if temp==. & share_foreign!=.
    svy: mean temp
    local allforeign = _b[temp]
    drop temp
    * share who report employment
    svy: mean employee
    local employed = _b[employee]
    svy, subpop(if female==0): mean employee
    * estimated number relying on job selling only to foreigners
    sum pweight
    di `allforeign' * `employed' * `r(sum)'
    * estimated number with customer base at least half but not all foreigners
    gen temp=1 if share_foreign>=.5 & share_foreign<1
    replace temp=0 if temp==. & share_foreign!=.
    svy: mean temp
    local mostlyforeign = _b[temp]
    drop temp
    sum pweight
    di `mostlyforeign' * `employed' * `r(sum)'
    * total number of adults in greater Monrovia
    sum pweight
    di `r(sum)'

    * business with at least 50% foreign customer base
    gen temp=1 if biz_foreign>=.5 & biz_foreign!=.
    replace temp=0 if temp==. & biz_foreign!=.
    svy: mean temp
    local lotsforeign = _b[temp]
    drop temp
    * share who report business
    svy: mean business
    local business = _b[business]
    * estimated number relying on business selling primarily to foreigners
    sum pweight
    di `lotsforeign' * `business' * `r(sum)'

    * share who report business and employment
    gen temp=1 if business==1 & employee==1
    replace temp=0 if business==0 | employee==0
    svy: mean temp
    drop temp
    * share who report either business or employment
    gen temp=1 if business==1 | employee==1
    replace temp=0 if temp==. & (business==0 | employee==0)
    svy: mean temp
    local working = _b[temp]
    drop temp
    * estimated number relying on either business or employment selling primarily to foreigners
    gen temp=1 if (biz_foreign>=.5 & biz_foreign!=.) | (share_foreign>=.5 & share_foreign!=.)
    replace temp=0 if temp==. & (biz_foreign!=. | share_foreign!=.)
    svy: mean temp
    local lotsforeign = _b[temp]
    drop temp
    sum pweight
    di `lotsforeign' * `working' * `r(sum)'

* Table 5
    * create education splines
    mkspline educspline1 .5 educspline2 1.5 educspline3 13.5 educspline4 14.5 educspline5 18.5 educspline6 19.5 educspline7 = education
    * sales to UN personnel and economic well-being
    svy: reg lnearnings pk_sold female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg lnassets pk_sold female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg asset_factor pk_sold female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg savings pk_sold female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu

* Table 6
    * recent sales to UN personnel and economic well-being
    svy: reg lnearnings i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg lnassets i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg asset_factor i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    svy: reg savings i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu

* Table 7
    * household death as economic shock
    svy: reg lnassets hh_death#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg asset_factor hh_death#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg enough_food hh_death#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg enough_housing hh_death#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg electricity hh_death#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu

* Figure 10
    * UNMIL popularity
    svy: mean pk_stay pk_safety pk_own_safety pk_positive pk_no_negative
    * estimates for receiving something of value
    svy: reg pk_stay pk_money female age married score hh_size lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    margins, predict() at(pk_money=(0 1))
    matrix out = r(b)
    svy: reg pk_safety pk_money female age married score hh_size lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    margins, predict() at(pk_money=(0 1))
    matrix out = out \ r(b)
    svy: reg pk_own_safety pk_money female age married score hh_size lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    margins, predict() at(pk_money=(0 1))
    matrix out = out \ r(b)
    svy: reg pk_positive pk_money female age married score hh_size lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    margins, predict() at(pk_money=(0 1))
    matrix out = out \ r(b)
    svy: reg pk_no_negative pk_money female age married score hh_size lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline* i.psu
    margins, predict() at(pk_money=(0 1))
    matrix out = out \ r(b)
    * export for plotting
    matrix colnames out = p0 p1
    preserve
        clear
        svmat out, names(col)
        outsheet using _out.csv, comma replace
    restore

* Table 8
    * concatenate multiple responses to question about negative consequences
    tempvar neg
    egen `neg'=concat(pk_negative_*), punct("; ")
    forval i = 1/5 {
        replace `neg'=regexr(`neg', "; ; ", "; ")
    }
    replace `neg'=regexr(`neg', "; ;", ";")
    replace `neg'=regexr(`neg', ";$", "")
    * create an indicator for each potential complaint, set to missing if underlying responses missing or refused
    tempvar dk reckless harass pregnancy economy slow bfgf bully prefer money jobs
    gen `dk'=1 if regexm(`neg', "^Don't know$") | regexm(`neg', "^Don't know; None$") | regexm(`neg', "^None$") | regexm(`neg', "^None; Don't know$")
    replace `dk'=0 if `dk'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `reckless'=1 if regexm(`neg', "Drive recklessly")
    replace `reckless'=0 if `reckless'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `harass'=1 if regexm(`neg', "harass local women")
    replace `harass'=0 if `harass'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `pregnancy'=1 if regexm(`neg', "Increase teenage pregnancy")
    replace `pregnancy'=0 if `pregnancy'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `economy'=1 if regexm(`neg', "harm the economy")
    replace `economy'=0 if `economy'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `slow'=1 if regexm(`neg', "slow down traffic")
    replace `slow'=0 if `slow'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `bfgf'=1 if regexm(`neg', "take our boyfriends / girlfriends")
    replace `bfgf'=0 if `bfgf'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `bully'=1 if regexm(`neg', "disrespect local citizens")
    replace `bully'=0 if `bully'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `prefer'=1 if regexm(`neg', "preferential treatment")
    replace `prefer'=0 if `prefer'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `money'=1 if regexm(`neg', "take money")
    replace `money'=0 if `money'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    gen `jobs'=1 if regexm(`neg', "take our jobs")
    replace `jobs'=0 if `jobs'!=1 & `neg'!="" & `neg'!="Refuse" & `neg'!="Refuse; Don't know"
    * proportion of subjects with each particular type of complaint
    foreach i of var `dk' `reckless' `harass' `pregnancy' `economy' `slow' `bfgf' `bully' `prefer' `money' `jobs' {
        svy: mean `i'
    }

* Table S.3
    * recent sales to UN personnel and economic well-being, post-1999 arrivals only
    * run without PSU indicators because of small sample size
    svy, subpop(if !regexm(location_1999, "Monrovia")): reg lnearnings i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline*
    svy, subpop(if !regexm(location_1999, "Monrovia")): reg lnassets i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline*
    svy, subpop(if !regexm(location_1999, "Monrovia")): reg asset_factor i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline*
    svy, subpop(if !regexm(location_1999, "Monrovia")): reg savings i.pk_sold_cat female age married score hh_size business employee lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai educspline*

* Table S.4
    * household death or injury as economic shock
    svy: reg lnassets hh_death_injury#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg asset_factor hh_death_injury#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg enough_food hh_death_injury#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg enough_housing hh_death_injury#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu
    svy: reg electricity hh_death_injury#pk_money female age married score lang_bassa lang_english lang_gbandi lang_gio lang_grebo lang_kpelle lang_krahn lang_lorma lang_mandingo lang_mano lang_vai i.psu

